package com.cskaoyan.catmall.controller.background;

import com.cskaoyan.catmall.model.pojo.keyword.KeywordPojo;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.keyword.GetListVo;
import com.cskaoyan.catmall.model.vo.keyword.KeywordVo;
import com.cskaoyan.catmall.service.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建日期: 2022/01/07 9:06
 *
 * @author WangZhe
 * 备注: 关键词controller
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @GetMapping("list")
    public BaseRespVo getListByKeywordAndUrl(Integer page, Integer limit, String sort, String order, String keyword, String url) {
        GetListVo vo = keywordService.getListByKeywordAndUrl(page, limit, sort, order, keyword, url);
        return BaseRespVo.ok(vo);
    }

    @PostMapping("create")
    public BaseRespVo createKeyWord(@RequestBody KeywordPojo keywordPojo){
        KeywordVo vo = keywordService.createKeyWord(keywordPojo);
        return BaseRespVo.ok(vo);
    }

    @PostMapping("delete")
    public BaseRespVo deleteKeyWord(@RequestBody KeywordPojo keywordPojo){
        keywordService.deleteKeyWord(keywordPojo.getId());
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo updateKeyWord(@RequestBody KeywordPojo keywordPojo){
        keywordService.updateKeyWord(keywordPojo);
        return BaseRespVo.ok();
    }

}
